package com.mogu.blogs.controller;

import com.mogu.blogs.service.BlogContentService;
import com.mogu.entity.TBlog;
import com.mogu.entity.TBlogSort;
import com.mogu.entity.TTag;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author muxiaofeng
 * @Date 2020/6/10 19:22.
 */
@RestController
@RequestMapping("/blogs")
public class BlogContentController {

    @Autowired
    BlogContentService blogContentService;

    /**
     * 通过uid查询博客内容
     * @param uid
     * @return
     */
    @ApiOperation(value = "通过uid查询博客内容" , notes = "通过uid查询博客内容")
    @RequestMapping(value = "/getBlogByUid/{uid}" , method = RequestMethod.GET)
    public TBlog getBlogByUid(@PathVariable String uid){

        return blogContentService.getBlogByUid(uid);
    }

    /**
     * 通过uid查询博客标签
     * @param uid
     * @return
     */
    @ApiOperation(value = "通过uid查询博客标签" , notes = "通过uid查询博客标签")
    @RequestMapping(value = "/getBlogContentByUid/{uid}" , method = RequestMethod.GET)
    public TTag getBlogContentByUid(@PathVariable String uid) {
        return blogContentService.getBlogContentByUid(uid);
    }

    /**
     * 通过uid查询点赞数
     * @param uid
     * @return
     */
    @ApiOperation(value = "通过uid查询点赞数" , notes = "通过uid查询点赞数")
    @RequestMapping(value = "/getBlogPraiseCountByUid/{uid}" , method = RequestMethod.GET)
    public TBlog getBlogPraiseCountByUid(@PathVariable String uid) {
        return blogContentService.getBlogPraiseCountByUid(uid);
    }

    /**
     * 通过uid给博客点赞
     * @param uid
     * @return
     */
    @ApiOperation(value = "通过uid给博客点赞" , notes = "通过uid给博客点赞")
    @RequestMapping(value = "/praiseBlogByUid/{uid}" , method = RequestMethod.GET)
    public String praiseBlogByUid(@PathVariable String uid) {
        try {
            blogContentService.praiseBlogByUid(uid);
            return "success";
        } catch (Exception e) {
            return "fail";
        }
    }

    /**
     * 通过标签的uid查询相关博客
     * @return
     */
    @ApiOperation(value = "通过标签的uid查询相关博客" , notes = "通过标签的uid查询相关博客")
    @RequestMapping(value = "/getTagContentByUid/{uid}" , method = RequestMethod.GET)
    public List<TBlog> getTagContentByUid(@PathVariable String uid) {
        return blogContentService.getTagContentByUid(uid);
    }

    /**
     * 通过uid查询分类名
     * @param uid
     * @return
     */
    @ApiOperation(value = "通过uid查询分类名" , notes = "通过uid查询分类名")
    @RequestMapping(value = "/getBlogSortContentByUid/{uid}" , method = RequestMethod.GET)
    public TBlogSort getBlogSortContentByUid(@PathVariable String uid) {
        return blogContentService.getBlogSortContentByUid(uid);
    }

    /**
     * 通过分类的uid查询相关博客
     * @param uid
     * @return
     */
    @ApiOperation(value = "通过分类的uid查询相关博客" , notes = "通过分类的uid查询相关博客")
    @RequestMapping(value = "/getSortContentByUid/{uid}" , method = RequestMethod.GET)
    public List<TBlog> getSortContentByUid(@PathVariable String uid) {
        return blogContentService.getSortContentByUid(uid);
    }

    /**
     * 查询相关文章标题
     * @return
     */
    @ApiOperation(value = "查询相关文章标题" , notes = "查询相关文章标题")
    @RequestMapping(value = "/getBlogTitle" , method = RequestMethod.GET)
    public List<TBlog> getBlogTitle() {
        return blogContentService.getBlogTitle();
    }

    /**
     * 通过标题名查询相关博客
     * @param title
     * @return
     */
    @ApiOperation(value = "通过标题名查询相关博客" , notes = "通过标题名查询相关博客")
    @RequestMapping(value = "/getBlogByBlogTitle/{title}" , method = RequestMethod.GET)
    public List<TBlog> getBlogByBlogTitle(@PathVariable String title) {
        return blogContentService.getBlogByBlogTitle(title);
    }

    /**
     * 通过作者查询相关博客
     * @param author
     * @return
     */
    @ApiOperation(value = "通过作者查询相关博客" , notes = "通过作者查询相关博客")
    @RequestMapping(value = "/getBlogByBlogAuthor/{author}" , method = RequestMethod.GET)
    public List<TBlog> getBlogByBlogAuthor(@PathVariable String author) {
        return blogContentService.getBlogByBlogAuthor(author);
    }

    /**
     * 通过分类名查询相关博客
     * @param sortName
     * @return
     */
    @ApiOperation(value = "通过分类名查询相关博客" , notes = "通过分类名查询相关博客")
    @RequestMapping(value = "/getBlogBySortName/{sortName}" , method = RequestMethod.GET)
    public List<TBlog> getBlogBySortName(@PathVariable String sortName) {
        return blogContentService.getBlogBySortName(sortName);
    }

    /**
     * 通过标签内容查询相关博客
     * @param content
     * @return
     */
    @ApiOperation(value = "通过标签内容查询相关博客" , notes = "通过标签内容查询相关博客")
    @RequestMapping(value = "/getBlogByTagContent/{content}" , method = RequestMethod.GET)
    public List<TBlog> getBlogByTagContent(@PathVariable String content) {
        return blogContentService.getBlogByTagContent(content);
    }
}
